<?php
    class Catalog_stuff extends Model {
        function __construct() {
            parent::Model();
        }

        function getAllStuffOffset($start = FALSE, $offset = FALSE) {
            $this->db->select('st.*, tr.title as tree_title');
            if($offset != FALSE && $start != FALSE) {
                $this->db->limit($start, $offset);
            }
            $this->db->join('tree tr', 'st.tree_id = tr.id', 'LEFT');

            $query = $this->db->get('stuff st');
            if($query->num_rows() > 0) {
                return $query->result_array();
            }

            return FALSE;
        }

        function getStuffByCategoryId($id) {
            $this->db->select('st.*, tr.title as tree_title');
            $this->db->where('st.active', 1);
            $this->db->where('st.tree_id', $id);
            $this->db->join('tree tr', 'st.tree_id = tr.id');
            $query = $this->db->get('stuff st');
            if($query->num_rows() > 0) {
                return $query->result_array();
            }

            return FALSE;
        }
        
        function getStuffItem($id) {
            $this->db->select('st.*');
            $this->db->from('stuff st');
            $this->db->where('st.id', $id);
            $this->db->where('st.active', 1);
            $query = $this->db->get();
            if($query->num_rows() > 0) {
                return $query->row_array();
            }
            
            return NULL;
        }
    }
?>